package com.javaweb.searchengine.app.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.javaweb.searchengine.app.domain.Product;
import com.javaweb.searchengine.app.repo.ProductRepository;

@Controller
public class SearchController {

	@Autowired
	private ProductRepository repo;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Map<String, Object> model) {
		return "search";
	}

	@ResponseBody
	@RequestMapping(value = "/dosearch", method = RequestMethod.POST)
	public List<Product> doSearch(String keyword) {
//		System.out.println(keyword);
		return repo.findByKeywordsContains(keyword);
	}
}
